var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/angular4");
mongoose.connection.on('connected', function () {
    console.log('connect mongodb success');
});
const models = {
    //注意这里user是表名,mongoose.model(name)里的那么要对应上这个user
    user: {
        username: {
            type: String,
            require: true
        },
        password: {
            type: String,
            require: true
        },
        createTime: {
            type: String,
            require: true,
            /*mongodb 设置字段默认值*/
            default: Date.now()
        },
        email: {
            type: String,
            require: true
        },
        sex: {
            type: String,
            require: true
        },
        birthDay: {
            type: String,
            require: true
        },

    }
}
for (var m in models) {
    mongoose.model(m, new mongoose.Schema(models[m]));
}
module.exports = {
    getModel: function (name) {
        return mongoose.model(name);
    }
}
